<?php

/**
 * 文件写操作类
 * 
 * @package    01CMS
 * @subpackage system
 * @author     rolong at vip.qq.com
 * @version    1.0.0
 * @link       http://www.01cms.com
 */

class Write
{

    /**
     * 将PHP数组写入文件
     * 
     * @param string $filePath 文件路径
     * @param array $array 数组值
     * @param string $comment 文件注释
     * @return int
     * @access public
     * @version 1.0.0 (2009-7-22)
     * @author rolong at vip.qq.com
     */
    public function phpArray ($filePath, $array, $comment = '')
    {
        $string = var_export($array, TRUE);
        
        if(!empty($comment))
        {
            $comment = str_replace("\r\n", "\n", $comment);
            $comment = str_replace("\n", "\n * ", $comment);
            $comment = "\n/**\n * {$comment}\n */\n";
        }
        
        return file_put_contents($filePath, "<?php{$comment}\nreturn {$string};");
    }
}

//End